using Core;

namespace g_gongjianta
{
    [Window((int)EWnd.MainWnd)]
    public class MainWnd : Window
    {
        //@formatter:off
        [UIField("root/touch")]
        private readonly UITouch uiTouch;
        [UIField("root/control/group/btn_1")]
        private readonly UISense btn1;
        [UIField("root/control/group/btn_2")]
        private readonly UISense btn2;
        [UIField("root/control/group/btn_3")]
        private readonly UISense btn3;
        [UIField("root/control/group/btn_all")]
        private readonly UISense btnAll;
        [UIField("root/control/group/btn_auto")]
        private readonly UIButton btnAuto;
        //@formatter:on

        private bool isAuto = false;

        protected override void OnShow()
        {
            var sys = G.Get<SenseSystem>();
            btn1.Bind(sys.GetSense("1"));
            btn2.Bind(sys.GetSense("2"));
            btn3.Bind(sys.GetSense("3"));
            btnAll.Bind(sys.GetAll());

            btnAuto.onClick += OnBtnAutoClickHandler;
        }

        protected override void OnClose()
        {
            btnAuto.onClick -= OnBtnAutoClickHandler;
        }

        private void OnBtnAutoClickHandler()
        {
            isAuto = !isAuto;

            btn1.Enable = btn2.Enable = btn3.Enable = btnAll.Enable = !isAuto;

            var sys = G.Get<SenseSystem>();

            foreach (var sense in sys.GetAll())
            {
                sense.IsOn = isAuto;
            }
        }
    }
}